/*
 * 文件名：RealStreamDataEncode.java
 * 版权：亚信联创版权所有
 * 描述：TODO
 * 修改人：napo
 * 修改时间：2014-11-13
 * 修改内容：TODO
 */
package com.ailk.bigdata.etl.realstream.server.netty.handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

import com.ailk.bigdata.etl.realstream.server.model.RealStreamDataPack;

/**
 * @description TODO
 * @author [xuwei3]
 * @version [版本号,2014-11-13]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class RealStreamDataEncode extends MessageToByteEncoder<RealStreamDataPack>
{

	/**
	 * @see io.netty.handler.codec.MessageToByteEncoder#encode(io.netty.channel.ChannelHandlerContext,
	 *      java.lang.Object, io.netty.buffer.ByteBuf)
	 */
	@Override
	protected void encode(ChannelHandlerContext ctx, RealStreamDataPack dataPack, ByteBuf out) throws Exception
	{
		byte[] content = dataPack.getSendContent().getBytes("utf-8");
		out.writeInt(dataPack.getDataType());
		out.writeInt(content.length);
		out.writeBytes(content);
		//dataPack = null;
	}

}
